﻿<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <script>
        //有一个对象 来判断是否有该属性 对象[`属性名`]
        let obj = {
            age: 18,
            sex:true
        }
        let temp = `age`;
        if (obj[temp]) {
            console.log(obj[temp]);
        } else {
            console.log(`no`);
        }
        // 判断一个字符串 'abcoefoxyozzopp' 中出现次数最多的字符，并统计其次数。
        /*
           对象 info
           info.a = 1
           info.b = 1
           info.c = 1
           info.o = 2
       */
        let result = `abcabaea`;
        let info = {};
       
        
        for (var i = 0; i < result.length; i++) {
            let char = result[i]
            if (info[char]) {
                info[char]++;

            } else {
                info[char] = 1;
               
            }
        }
        console.log(info);
        //遍历对象的属性和值
        let max = 0;
        let ch = ``;
        for (var k in info) {
            console.log(k, info[k]);
            if (info[k]>max) {
                max = info[k];
                ch = k;
            }
        }
        console.log(ch,max);
    </script>
</body>
</html>
